package calao.client.util;

public class Arrays 
{
	
	public static int[] copyOf(int[] array, int newSize)
	{
		int[] result = new int[newSize];
		for (int i=0; i<newSize; i++) result[i] = i<array.length? array[i] : 0;
		return result;
	}

	public static int[] copyOf(int[] array)
	{
		return copyOf(array, array.length);
	}

	public static long[] copyOf(long[] array, int newSize)
	{
		long[] result = new long[newSize];
		for (int i=0; i<newSize; i++) result[i] = i<array.length? array[i] : 0;
		return result;
	}	
	
	public static long[] copyOf(long[] array)
	{
		return copyOf(array, array.length);
	}

	public static boolean contains(int[] array, int value)
	{
		for (int i=0; i<array.length; i++) {
			if (array[i]==value) return true;
		}
		return false;
	}

	public static boolean contains(String[] array, String value)
	{
		for (int i=0; i<array.length; i++) {
			if (array[i].equals(value)) return true;
		}
		return false;
	}
	
	public static int[] add(int[] array, int value)
	{
		if (contains(array, value)) return array;
		int[] result = copyOf(array, array.length+1);
		result[array.length] = value;
		return result;
	}

}
